package org.example.admin.service.impl;

import org.example.admin.exception.ServiceException;
import org.example.admin.mapper.ReportMapper;
import org.example.admin.mapper.ReportcaMapper;
import org.example.admin.mapper.ReportorMapper;
import org.example.admin.service.ReportService;
import org.example.entity.Cart;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ReportServiceImpl implements ReportService {

    @Resource
    public ReportMapper reportMapper;

    @Resource
    public ReportorMapper reportorMapper;

    @Resource
    public ReportcaMapper reportcaMapper;

    @Override
    public List<Cart> getCartInfo() {
        List<Cart> cartInfo = null;
        try{
            cartInfo = reportcaMapper.getCartInfo();
        }catch (Exception e){
            e.printStackTrace();
            throw new ServiceException("service层异常");
        }
        return cartInfo;
    }

    @Override
    public int getNums() {
        Integer count = 0;
        try{
            count = reportMapper.getNums();
        }catch (Exception e){
            e.printStackTrace();
            throw new ServiceException("service层异常");
        }


        return count;
    }

    @Override
    public List<Map<String, String>> getNearly7Days() {
        List<Map<String,String>> list = null;
        try{
            list = reportMapper.getNearly7Days();
        }catch (Exception e){
            e.printStackTrace();
            throw new ServiceException("service层异常");
        }
        return list;
    }

    @Override
    public List<Map<String, String>> getNearly30Days() {
        List<Map<String,String>> list = null;
        try{
            list = reportMapper.getNearly30Days();
        }catch (Exception e){
            e.printStackTrace();
            throw new ServiceException("service层异常");
        }
        return list;
    }

    @Override
    public Map<String, List> getSales() {
        Map<String,List> data = new HashMap<>();
        List<String> goodsType = null;
        List<BigDecimal> goodsSales = null;
        try{
            //获取商品分类名称
            goodsType = reportorMapper.getGoodsType();
            //获取分类商品的销售额
            goodsSales =  reportorMapper.getGoodsSales();
            data.put("xAxis",goodsType);
            data.put("series",goodsSales);
        }catch (Exception e){
            e.printStackTrace();
            throw new ServiceException("service层异常");
        }

        return data;
    }

    @Override
    public long getTotalSales() {
        long total = 0L;
        try{
            total = reportorMapper.getTotalSales();
        }catch (Exception e){
            e.printStackTrace();
            throw new ServiceException("service层异常");
        }
        return total;
    }

    @Override
    public List<Map<String, String>> getSalesShare() {
        List<Map<String,String>> list = null;
        try{
            list = reportorMapper.getSalesShare();
        }catch (Exception e){
            e.printStackTrace();
            throw new ServiceException("service层异常");
        }
        return list;
    }


}
